home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Apps / ArchiveUtils / backupod / backup.od next >
Encoding:
Text File  |  1992-12-20  |  4.5 KB  |  153 lines

  1. #! /bin/sh
  2. # backup.od [ -a time ] [-m] [ dir ]
  3. # version 2.2, 11 July 1990.
  4. #
  5. # Back up files rooted at dir (default is $HOME) since last backup.
  6. # Backup is a tar file and is saved to /backup/$(USER) on
  7. # sv.<month>.<day>.<hour>.tar
  8. # where month, day and hour encode the date and time.
  9. # A long directory listing of all files backed up is saved to 
  10. # sv.<month>.<day>.<hour>.lst.
  11. # Leaves a .backup.od file in dir, which lists the backup file,
  12. # date and time, and files backed up; the timestamp
  13. # of .backup.od file is used as time of `last backup'.
  14. #
  15. # If .backup.od doesn't exist or can't be read, all files are backed up
  16. # and the backup is saved to fl.<month>.<day>.<hour>.tar
  17. # where month, day and hour encode the date and time as above.
  18. # The long directory listing is stored in fl.<month>.<day>.<hour>.lst
  19. #
  20. # The -a option causes backup to schedule a backup at `time' and everyday
  21. # thereafter at the same time. Time is any time accepted by the at(1)
  22. # command. When the -a given, backup mails the standard output and error
  23. # of the backup run to the user.
  24. #
  25. # The -m option causes a request to mount an optical disk in drive 0 to be
  26. # issued before the backup is made.  After the backup finished, the optical
  27. # disk will be unmounted and ejected.
  28. #
  29.  
  30. # This script was originally written by Dr. Dave Hanson, Princeton University,
  31. # while at Los Alamos in the summer of 1987.  It has been extensively modified
  32. # and ported to the NeXT by Pat McGee, Computer Graphics Group, Los Alamos National Laboratory.
  33.  
  34. #    Copyright, 1990, The Regents of the University of
  35. #    California.  This software was produced under a U. S.
  36. #    Government contract (W-7405-ENG-36) by the Los Alamos
  37. #    National Laboratory, which is operated by the 
  38. #    University of California for the U. S. Department of
  39. #    Energy.  The U. S. Government is licensed to use,
  40. #    reproduce, and distribute this software.  Permission
  41. #    is granted to the public to copy and use this software
  42. #    without charge, provided that this Notice and any statement
  43. #    of authorship are reproduced on all copies.  Neither the
  44. #    Government nor the University makes any warranty, express
  45. #    or implied, or assumes any liability or responsibility for
  46. #    the use of this software.
  47.  
  48. trap "rm -f /tmp/$$; exit 1" 1 2 15
  49.  
  50. progname=$0
  51. timefile=.backup.od
  52.  
  53. mount=
  54. at=
  55. attime=
  56. if [ "$1" = "-m" ]; then
  57.     mount="-m"
  58.     if [ "$2" = "-a" ]; then
  59.         at="-a"
  60.         attime=$3
  61.         dir=${4-$HOME}
  62.     else
  63.         dir=${2-$HOME}
  64.     fi
  65. elif [ "$1" = "-a" ]; then
  66.     at="-a"
  67.     attime=$2
  68.     if [ "$3" = "-m" ]; then
  69.         mount="-m"
  70.         dir=${4-$HOME}
  71.     else
  72.         dir=${3-$HOME}
  73.     fi
  74. else
  75.     dir=${1-$HOME}
  76. fi
  77.  
  78. if [ "$at" = "-a" ]; then
  79.         SHELL=/bin/sh at $attime <<End
  80. $progname $mount $dir 2>&1 | mail -s "\`date\` $progname" $USER
  81. sleep 1200
  82. $progname $mount -a $attime $dir
  83. End
  84.     exit 0
  85. fi
  86.  
  87. #things to configure
  88. budir=/tmp/backup
  89. if [ "$mount" = "-m" ]; then
  90.     savedir=${budir}
  91. else
  92.     savedir=${budir}/$USER
  93. fi
  94.  
  95. if [ "$mount" = "-m" ]; then
  96.     mountod ${budir}
  97. fi
  98.  
  99. if [ ! -d ${savedir} ]; then
  100.     echo "${savedir} not found"
  101.     exit 1
  102. fi
  103.  
  104. cd $dir
  105. if [ ! -r ${timefile} ]; then
  106.     #full backup
  107.     basename=`date | tr A-Z: a-z'\040' | awk '{ printf "fl.%s.%02d.%s.", $2, $3, $4}'`
  108.     savename=${basename}tar
  109.     savedirname=${basename}lst
  110.     if ls $savedir | grep $savename ; then 
  111.         echo "overwritten" ; fi
  112.     find . ! -type d -print >/tmp/$$
  113.     if tar cf ${savedir}/${savename} . ; then
  114.         (echo $savedir/$savename `date`; cat /tmp/$$) >${timefile} ;
  115.         else exit 1 ;
  116.     fi
  117.     echo "tar file written"
  118.     rm -f /tmp/$$
  119. # comment out the next 3 lines to avoid writing the list file
  120.     find . ! -type d -exec ls -l "{}" \; > /tmp/$$ 
  121.     if cp /tmp/$$ ${savedir}/${savedirname}  ; \
  122.          then echo  ;  else exit ; fi
  123. # end of list file generation
  124.     echo "backup.od done"
  125.     df $savedir
  126.     ls $savedir
  127. else
  128.     # incremental backup
  129.     basename=`date | tr A-Z: a-z'\040' | awk '{ printf "sv.%s.%02d.%s.", $2, $3, $4}'`
  130.     savename=${basename}tar
  131.     savedirname=${basename}lst
  132.     if ls ${savedir} | grep $savename ; then echo \
  133.         "file already exists" ; exit  ; fi
  134.     find . ! -type d -newer ${timefile} -print >/tmp/$$
  135.     if tar cf ${savedir}/${savename} `cat /tmp/$$` ; \
  136.      then (echo $savedir/$savename `date`; cat /tmp/$$) >${timefile}  ;
  137.     else exit 1 ; fi
  138.     echo "tar file written"
  139. # comment out the next 3 lines to avoid writing the list file
  140.         if ls -l `cat /tmp/$$` | \
  141.          cat - >  ${savedir}/${savedirname}  ; then echo  ; \
  142.         else exit ; fi
  143. # end of list file generation
  144.     echo "backup.od done"
  145.     df $savedir
  146.     ls $savedir
  147. fi
  148. rm -f /tmp/$$
  149. if [ "$mount" = "-m" ]; then
  150.     unmountod
  151. fi
  152. exit 0
  153.